package cn.tedu.boot41.Controller;

import cn.tedu.boot41.Mapper.EmpMapper;
import cn.tedu.boot41.entity.Emp;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmpController {

    @Autowired(required = false)
    private EmpMapper mapper;

    @RequestMapping("/insert")
    public void insert(@RequestBody Emp emp){
        System.out.println(emp.toString());
        mapper.insert(emp);
    }

    @RequestMapping("/select")
    public List<Emp> select(){
        return mapper.select();
    }

    @RequestMapping("/delete")
    public void delete(int id){
        System.out.println(id);
        mapper.delete(id);
    }

    @RequestMapping("/selectById")
    public Emp selectById(int id){
        System.out.println(id);
        Emp emp = mapper.selectById(id);
        return emp;
    }

    @RequestMapping("/update")
    public void update(@RequestBody Emp emp){
//        Emp emp1 = mapper.selectById(emp.getId());
        mapper.update(emp);
    }


}
